package sgfapp.uno;

//import sgfapp.uno.activity_menu.MiLocationListener;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMapOptions;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.google.android.gms.maps.model.MarkerOptions;
public class activity_alta  extends Activity implements OnClickListener {

	static int Instancias;
//	TextView text;
	ImageView imv;
	ImageView imv2;
	ImageView imv3;
	Button boton;
	Intent i;
	final static int cons=0;
	Bitmap bmp;
	private final LatLng LOCATION_BURNABY = new LatLng(49.27645, -122.917587);
	private final LatLng LOCATION_SURRREY = new LatLng(49.187500, -122.849000);
	private GoogleMap map;
	EditText texto;
	TextView textviewgracias;

	void activiti_alta(){
		Instancias++;
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.activity_alta);
		init();
		LocationManager milocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
	    LocationListener milocListener = new MiLocationListener();
	    milocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, milocListener);
       // text = (TextView)findViewById(R.id.textView1);
     //   text.setText("Cambio Texto");
        


	}
	
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
 
        return true;
    }
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
	    // Handle item selection
	    switch (item.getItemId()) {
	        case R.id.logout:

		    	Intent intent = new Intent(this, MainActivity.class);
		        startActivity(intent);
		        finish();
	        case R.id.action_info:

		    	Intent intent2 = new Intent(this, Info.class);
		        startActivity(intent2);
		        
	    }
	    return true;
	}
	public void init()
	{

		
		
		
		
		
		Log.e("GCMDemo","2");
		//LatLngBounds AUSTRALIA = new LatLngBounds(new LatLng(-44, 113), new LatLng(-10, 154));
		//xmap.setIndoorEnabled(true);
		//map.addMarker(new MarkerOptions().position(LOCATION_SURRREY).title("Find me here!"));
		Log.e("GCMDemo","3");
		//map.moveCamera(CameraUpdateFactory.newLatLngZoom(LOCATION_SURRREY, 15));
///		map.moveCamera(CameraUpdateFactory.newLatLngBounds(AUSTRALIA, 0));
		imv=(ImageView)findViewById(R.id.imageView1);
		Log.e("GCMDemo","4");
		//imv2=(ImageView)findViewById(R.id.imageView2);
		Log.e("GCMDemo","5");
		imv3=(ImageView)findViewById(R.id.imageView3);
		Log.e("GCMDemo","6");
		//boton=(Button)findViewById(R.id.button1);
		texto=(EditText)findViewById(R.id.editText1);
		textviewgracias=(TextView)findViewById(R.id.textView1);
		Log.e("GCMDemo","7");
		//imv2.setOnClickListener(this);
		Log.e("GCMDemo","8");
		
		
		try{
			Log.e("GCMDemo","1");
			map  = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
			map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
		}catch(Exception e)
		{
			Log.e("GCMDemo","2"+e.toString());
		}

		
	}
public class MiLocationListener implements LocationListener
{
    public void onLocationChanged(Location loc)
    {
    	
	    loc.getLatitude();
	    loc.getLongitude();
	    String coordenadas = "Mis coordenadas son: " + "Latitud = " + loc.getLatitude() + "    Longitud = " + loc.getLongitude();
	    LatLng LOCATION = new LatLng(loc.getLatitude() , loc.getLongitude());
		map  = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
		
		map.animateCamera(CameraUpdateFactory.newLatLngZoom(LOCATION,18));
	    //Toast.makeText( getApplicationContext(),coordenadas,Toast.LENGTH_LONG).show();
        //text = (TextView)findViewById(R.id.textView1);
       // text.setText(coordenadas);
    }
    public void onProviderDisabled(String provider)
    {
	    //Toast.makeText( getApplicationContext(),"Gps Desactivado",Toast.LENGTH_SHORT ).show();
    	//text.setText("Gps Desactivado");
    }
    public void onProviderEnabled(String provider)
    {
    //Toast.makeText( getApplicationContext(),"Gps Activo",Toast.LENGTH_SHORT ).show();
    	//text.setText("Gps Activo");
    }
    public void onStatusChanged(String provider, int status, Bundle extras){}
    }





	@Override
	public void onClick(View v)
	{
		int id;
		id=v.getId();
		switch(id)
		{
		case R.id.camara:
			i=new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
			startActivityForResult(i,cons);
			break;
		}
	}
	
	
	
	
	@Override
	protected void onActivityResult(int RequestCode,int ResultCode,Intent data){
		super.onActivityResult(RequestCode, ResultCode, data);
		if(ResultCode==Activity.RESULT_OK)
		{
			Bundle ext= data.getExtras();
			bmp =(Bitmap)ext.get("data");
			imv.setImageBitmap(bmp);
		}
	}

	public void onClick_City(View v) {
//		CameraUpdate update = CameraUpdateFactory.newLatLng(LOCATION_BURNABY);
		map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
		CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_BURNABY, 9);
		map.animateCamera(update);
	}
	public void onClick_Burnaby(View v) {
		map.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
		CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_BURNABY, 14);
		map.animateCamera(update);
		
	}
	public void onClick_Surrey(View v) {
		map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
		CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_SURRREY, 16);
		map.animateCamera(update);
		
	}
}
